# import time
# from pathlib import Path
#
# from PIL import Image
#
#
# def encrypt(str_1, str_2):
#     if len(str_1 + str_2) == 2:
#         return str_1 + '00' + str_2
#     elif len(str_1 + str_2) == 3:
#         return str_1 + '0' + str_2
#     elif len(str_1 + str_2) == 4:
#         return str_1 + str_2
#     else:
#         return str_1 + str_2
#
#
# if __name__ == '__main__':
#     '''
#     地图合并
#     '''
#     print('开始')
#     timestamp = int(time.time())
#     original_file_path = "D:\\1\\"
#     final_file_path = 'D:\\2\\'
#     # 单张图片宽度
#     dd_width = 0
#     # 单张图片高度
#     dd_height = 0
#     # 横向有多少张图片
#     x_number = 0
#     # 竖向有多少张图片
#     y_number = 0
#     my_map = {}
#     folder_path = Path(original_file_path)
#     for file in folder_path.rglob("*"):
#         if file.is_file():
#             qian_zhui = str(file)[:-8]
#             if qian_zhui in my_map:
#                 arr = my_map[qian_zhui]
#                 arr.append(file)
#             else:
#                 arr = []
#                 arr.append(file)
#                 my_map[qian_zhui] = arr
#     for key, value in my_map.items():
#         bb = key.replace('D:\\1\\', 'D:\\2\\')
#         cc = Path(bb).parent
#         aa = 0
#         dd_width = 0
#         dd_height = 0
#         for file in value:
#             image1 = Image.open(str(file))
#             if dd_width < image1.width:
#                 dd_width = image1.width
#             if dd_height < image1.height:
#                 dd_height = image1.height
#             qian_zhui = int(str(file)[-8:-7])
#             if aa < qian_zhui:
#                 aa = qian_zhui
#         x_number = int(len(value) / (aa + 1))
#         y_number = qian_zhui + 1
#         new_image = Image.new('RGBA', (dd_width * x_number, dd_height * y_number))
#         for x in range(x_number):
#             for y in range(y_number):
#                 image1 = Image.open(key + encrypt(str(y), str(x)) + '.png')
#                 new_image.paste(image1, (dd_width * x, dd_height * y))
#         dir_path = Path(cc)
#         dir_path.mkdir(parents=True, exist_ok=True)
#         new_image.save(key.replace('D:\\1\\', 'D:\\2\\') + ".png")
#         for file in value:
#             Path(file).unlink()
#     endTime = int(time.time())
#     print(str(endTime - timestamp))
#     print('结束')